<template>
    <view v-if="show">
		<view class="ker_notice_bar">
			<view class="ker_notice_icon" v-if="icon">
				<image src="../../static/notice_icon.png" mode=""></image>
			</view>
			<view class="ker_notice_msg" :class="{'w_30':list.length}">
				<view class="ker_notice_msg_content" :class="{'marquee_left':animateLeft,'wrap':isWarp}" v-if="text">
					{{text}}
				</view>
				<view class="ker_notice_content" v-if="list.length" :class="{'marquee_top':animate}">
					<view class="ker_notice_item" v-for="(item,index) in list" :key="index">
						{{item}}
					</view>
				</view>
			</view>
			<view class="ker_notice_close" v-if="close" @click="chageClose">
				<image src="../../static/close_icon.png" mode=""></image>
			</view>
		</view>
    </view>
</template>
<script>
export default {
	data() {
	  return {
		animate:false,
		time:null,
		show:true
	  }
	},
	props:{
		list:{	//垂直滚动列表
			type:Array,
			default:function (){
				return []
			},
		},
		text:{	//文本
			type:String,
			default:''
		},
		close:{	//关闭
			type:Boolean,
			default:false
		},
		icon:{	//图标
			type:Boolean,
			default:true
		},
		animateLeft:{	//从右到左滚动
			type:Boolean,
			default:true
		},
		isWarp:{	//单行css超出部分省略号显示
			type:Boolean,
			default:false
		}
	},
	methods:{
		showMarquee: function () {
			this.animate = true;
			setTimeout(()=>{
				this.list.push(this.list[0]);
				this.list.shift();
				this.animate = false;
			},500)
		},
		chageClose(){
			this.show = false
		}
	},
	mounted() {
		if(this.list.length){
			this.time = setInterval(this.showMarquee, 3000)
		}
	},
	destroyed() {
		clearInterval(this.time)
	}
}
</script>
<style lang='scss' scoped>
.ker_notice_bar{
	background-color: #fffbe8;
	display: flex;
	/* align-items: center; */
	padding: 5px 10px;
	.ker_notice_icon{
		width: 20px;
		height: 20px;
		margin-right: 10px;
		margin-top: 5px;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.ker_notice_msg{
		position:relative;
		width: 100%;
		color: #ed6a0c;
		font-size: 14px;
		display: block;
		overflow: hidden;
		flex: 1;
		&.w_30{
			height: 30px;
		}
		.ker_notice_content{
			position: absolute;
			top: 0;
			left: 0;
			&.marquee_top {
				transition: all 0.5s;
				margin-top: -30px
			}
			.ker_notice_item{
				height: 30px;
				line-height: 30px;
				font-size: 14px;
			}
		}
		.ker_notice_msg_content{
			line-height: 30px;
		}
		.wrap{
			overflow: hidden;
			text-overflow:ellipsis;
			white-space: nowrap;
		}
		.marquee_left{
			margin-left: 100%; // 把文字弄出可见区域
			width: 180%;
			animation: myMove 6s linear infinite; // 重点，定义动画
			animation-fill-mode: forwards;
		}
	}
	.ker_notice_close{
		width: 30px;
		height: 30px;
		display: flex;
		align-items: center;
		justify-content: center;
		image{
			width: 15px;
			height:15px;
		}
	}
}
 /*文字无缝滚动*/
  @keyframes myMove {
    0% {
      transform: translateX(0);
    }
    100% {
      transform: translateX(-100%);
    }
  }
</style>